

package com.teaching.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.teaching.common.Result;

import com.teaching.dto.SubjectReplyDTO;
import com.teaching.entity.SubjectReply;
import com.teaching.mapper.SubjectReplyMapper;
import com.teaching.service.SubjectReplyService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 论坛留言表
 *
 * @author xubb
 * @date 2021-03-22 15:29:30
 */
@RestController
@AllArgsConstructor
@RequestMapping("/subjectreply" )
@Api(value = "subjectreply", tags = "论坛留言表管理")
public class SubjectReplyController {
    @Resource
    private SubjectReplyService subjectReplyService;

    @Resource
    private SubjectReplyMapper subjectReplyMapper;

    /**
     * 分页查询
     *
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @PostMapping("/getSubjectReplyList")
    public Result<IPage<SubjectReply>> getSubjectReplyList(@RequestBody SubjectReplyDTO dto) {
        Page<SubjectReply> page = new Page<>(dto.getPageNo(), dto.getPageSize());
        SubjectReply subjectReply = new SubjectReply();
        BeanUtil.copyProperties(dto,subjectReply);
        return Result.success(subjectReplyMapper.getSubjectReplyList(page, subjectReply));
    }


    /**
     * 通过id查询
     *
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @PostMapping("/getSubjectReplyInfo")
    public Result getSubjectReplyInfo(@RequestBody SubjectReply subjectReply) {
        return Result.success(subjectReplyService.getById(subjectReply.getId()));
    }

    /**
     * 新增
     *
     * @param subjectReply
     * @return R
     */
    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/save")
    public Result save(@RequestBody SubjectReply subjectReply) {

        return Result.success(subjectReplyService.save(subjectReply));
    }

    /**
     * 修改
     *
     * @param subjectReply
     * @return R
     */
    @ApiOperation(value = "修改", notes = "修改")
    @PostMapping("/updateById")
    public Result updateById(@RequestBody SubjectReply subjectReply) {

        return Result.success(subjectReplyService.updateById(subjectReply));
    }

    /**
     * 通过id删除
     *
     * @return R
     */
    @ApiOperation(value = "通过id删除", notes = "通过id删除")
    @PostMapping("/removeById")
    public Result removeById(@RequestBody SubjectReply subjectReply) {
        return Result.success(subjectReplyService.removeById(subjectReply.getId()));
    }

}
